from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time
class Base():
    # 初始化driver
    def __init__(self,driver):
        self.driver = driver


    # 打开网页
    def open_url(self,url):
        self.driver.get(url)

    # 封装find_ments
    def find_element(self,loc):
        try:
            WebDriverWait(self.driver,20,0.5).until(EC.presence_of_element_located(loc))
            return self.driver.find_element(*loc)
        except Exception as e:
            a=time.strftime('%Y%m%d%H%M%S')
            self.driver.save_screenshot(time.strftime('%Y%m%d%H%M%S'+'a.png'))
            print(a)
            print(e)


    def click(self,loc):
        self.find_element(loc).click()


    def send_keys(self,loc,info):
        self.find_element(loc).send_keys(info)

    def frame(self,loc):
        self.driver.switch_to.frame(self.find_element(loc))

    def defauit_frame(self):
        self.driver.switch_to.default_content()



